package com.kitty.game.bag.controller;

import com.kitty.game.bag.message.ReqFlyState;
import com.kitty.game.bag.message.RespUpdateUnique;
import com.kitty.game.fight.service.BroadcastService;
import com.kitty.game.role.model.Role;
import com.kitty.game.role.service.RoleService;
import com.kitty.game.team.model.Member;
import com.kitty.game.team.model.Team;
import com.kitty.game.team.service.TeamService;
import com.kitty.mina.annotation.RequestMapping;
import com.kitty.mina.cache.SessionUtils;
import com.kitty.mina.message.MessagePusher;
import lombok.extern.slf4j.Slf4j;
import org.apache.mina.core.session.IoSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

@Controller
@Slf4j
public class flyStateController {
    @Autowired
    BroadcastService broadcastService;
    @Autowired
    TeamService teamService;
    @Autowired
    RoleService roleService;
    @RequestMapping
    public void openGuiChong(IoSession session, ReqFlyState reqFlyState) {
        Role role = SessionUtils.getRoleBySession(session);
        //飞行器开关
        if("fly_stop".equals(reqFlyState.getType())){
            role.getPropsStatus().setv("fly_status", reqFlyState.getStatus());
        }
        //气场特效
        if("hide_wandao_effect".equals(reqFlyState.getType())){
            role.getPropsStatus().setv("hide_wandao_effect", reqFlyState.getStatus());
            RespUpdateUnique respUpdateUnique = new RespUpdateUnique();
            respUpdateUnique.setKey("hide_wandao_effect");
            respUpdateUnique.setFlag(reqFlyState.getStatus());
            MessagePusher.pushMessage(role, respUpdateUnique);
            if(reqFlyState.getStatus()==0){
                int icon = role.getPropsStatus().getInt("wandan_effect", 0);
                role.setEffectIcon(icon);
            }else{
                role.setEffectIcon(0);
            }
        }
        if(teamService.isInTeam(role)){
            if( teamService.isTeamLeader(role)){
                Team team = teamService.getTeam(role.getRoleId());
                for (Member member : team.getList()) {
                    Role memberRole = roleService.getOnlinePlayer(member.getUid());
                    if(memberRole !=null && member.isInTeam()){
                        broadcastService.sendUpdateAppear(memberRole);
                    }
                }
            }
        }else{
            broadcastService.sendUpdateAppear(role);
        }
    }
    public int getEffectByName(String name){
        int icon=0;
        if("万道袍·一元初始".equals(name) || "万道衣·一元初始".equals(name)){
            icon=2271;
        }else if("万道袍·两仪阴阳".equals(name) || "万道衣·两仪阴阳".equals(name)){
            icon=2272;
        }else if("万道袍·三才合一".equals(name) || "万道衣·三才合一".equals(name)){
            icon=2273;
        }else if("万道袍·四象轮回".equals(name) || "万道衣·四象轮回".equals(name)){
            icon=2274;
        }else if("万道袍·五行聚源".equals(name) || "万道衣·五行聚源".equals(name)){
            icon=2275;
        }else if("万道袍·六合天更".equals(name) || "万道衣·六合天更".equals(name)){
            icon=2276;
        }else if("万道袍·七星渡世".equals(name) || "万道衣·七星渡世".equals(name)){
            icon=2277;
        }else{
            icon=0;
        }
        return icon;
    }
}
